﻿using System;
using System.Data;
using VOL.Entity.DomainModels;
using VOL.Wms.IServices;

namespace VOL.WebApi.VOL.WebApi.Operator.Wms
{
    public class Bus_DeliveryVOperator
    {
        internal static bool ReceiveDeliveryOperator(Bus_DeliveryV bus_deliveryv, IBus_DeliveryVService _service,out string errMsg)
        {
            errMsg = string.Empty;
            string sql;
            string VolumeCodeNew;
            return _service.DoReceiveDelivery(bus_deliveryv,out errMsg);
            //sql = "select DocCode from Bus_DeliveryV where DocCode='"+ bus_deliveryv.DocCode.Trim().Replace("--","") + "' ";

            //      DataTable tb= WmsPub.SqlQuery(sql);
            //      if (tb != null)
            //      {
            //          if (tb.Rows.Count > 0)
            //          {
            //              errMsg = "单号"+ bus_deliveryv.DocCode+"已经存在了";
            //              return false;
            //          }
            //          else
            //          {
            //              foreach (Bus_DeliveryVolume bus_DeliveryVolume in bus_deliveryv.Bus_DeliveryVolume)
            //              {
            //                  //检查表体
            //                  VolumeCodeNew = bus_DeliveryVolume.VolumeNumber.Trim().Replace("--", "") + "' ";
            //sql = " select VolumeNumber  from Bus_DeliveryVolume  where VolumeNumber='" + VolumeCodeNew + "'  ";
            //sql += " group by VolumeNumber having sum(tag)>0";
            //                  DataTable tb2 = WmsPub.SqlQuery(sql);
            //                  if (tb2!=null)
            //                  {
            //                      if (tb2.Rows.Count>0)
            //                      {
            //                          errMsg = "单号[" + bus_deliveryv.DocCode + "]的卷号]"+ VolumeCodeNew+"]已经存在了";
            //                          return false;
            //                      }
            //                  }
            //                  else
            //                  {
            //                  }
            //              }
            //              //开始塞入
            //              //string guid = Guid.NewGuid().ToString();
            //              //sql = " insert into Bus_DeliveryV (guid, WorkShopCode, WorkShopName, DocCode, DeliveryDate, DeliveryAddress, DepartmentCode, DepartmentName, ";
            //              //sql +=" CustomerCode, CustomerName, CreatorCode, CreatorName, ContactName, ContactPhone, Remark) ";
            //              //sql += " values ('" + guid + "','" + bus_deliveryv.WorkShopCode + "','" + bus_deliveryv.WorkShopName + "',";
            //              //sql +="'"+ bus_deliveryv.DocCode + "','"+ bus_deliveryv.DeliveryDate + "','"+ bus_deliveryv.DeliveryAddress + "','"+ bus_deliveryv.DepartmentCode + "',) ";
            //              //sql += "'" + bus_deliveryv.DepartmentName + "','" + bus_deliveryv.CustomerCode + "','" + bus_deliveryv.CustomerName + "','" + bus_deliveryv.CreatorCode + "', ";
            //              //sql += "'" + bus_deliveryv.CreatorName + "','" + bus_deliveryv.ContactName + "','" + bus_deliveryv.ContactPhone + "','" + bus_deliveryv.Remark + "') ";

            //              //foreach (Bus_DeliveryVolume bus_DeliveryVolume in bus_deliveryv.Bus_DeliveryVolume)
            //              //{
            //              //    sql += " insert into Bus_DeliveryVolume( guid, bguid, DocCode, RowNumber, VolumeNumber, InventoryCode, WarehouseCode, WarehouseName, LocationCode, ";
            //              //    sql +=" LocationName, Size, Weight, RowRemark, tag, status   ";
            //              //    sql += " values ('"+ guid + "',newid(),'" + bus_deliveryv.WorkShopCode + "','" + bus_deliveryv.WorkShopName + "'," :




            //              //}



            //          }
            //      }
            //return true;
        }
    }
}
